package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapePic;
import com.ruoyi.grape.service.IGrapePicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 摄像头图片信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/pic")
public class GrapePicController extends BaseController
{
    @Autowired
    private IGrapePicService grapePicService;

    /**
     * 查询摄像头图片信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapePic grapePic)
    {
        startPage();
        List<GrapePic> list = grapePicService.selectGrapePicList(grapePic);
        return getDataTable(list);
    }
    /**
     * 获取最近七天摄像头采集到的图片信息
     */
   @PreAuthorize("@ss.hasPermi('grape:pic:recent')")
    @GetMapping("/recent")
    public  AjaxResult getRecentPic(GrapePic grapePic){
//        List<GrapePic> recentlist=grapePicService.selectGrapePicByRecentId();
   return success(grapePicService.selectGrapePicByRecentId());


    }

    /**
     * 导出摄像头图片信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:export')")
    @Log(title = "摄像头图片信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapePic grapePic)
    {
        List<GrapePic> list = grapePicService.selectGrapePicList(grapePic);
        ExcelUtil<GrapePic> util = new ExcelUtil<GrapePic>(GrapePic.class);
        util.exportExcel(response, list, "摄像头图片信息数据");
    }

    /**
     * 获取摄像头图片信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:query')")
    @GetMapping(value = "/{picId}")
    public AjaxResult getInfo(@PathVariable("picId") Long picId)
    {
        return success(grapePicService.selectGrapePicByPicId(picId));
    }

    /**
     * 新增摄像头图片信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:add')")
    @Log(title = "摄像头图片信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapePic grapePic)
    {
        return toAjax(grapePicService.insertGrapePic(grapePic));
    }

    /**
     * 修改摄像头图片信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:edit')")
    @Log(title = "摄像头图片信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapePic grapePic)
    {
        return toAjax(grapePicService.updateGrapePic(grapePic));
    }

    /**
     * 删除摄像头图片信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pic:remove')")
    @Log(title = "摄像头图片信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{picIds}")
    public AjaxResult remove(@PathVariable Long[] picIds)
    {
        return toAjax(grapePicService.deleteGrapePicByPicIds(picIds));
    }
}
